<template>
	<view class="" style="background-color: #b10021;">
		<view class="content">
			<view class="topOne">
				<image src="/static/image/index_text1.png" mode="" class="indexText"></image>
			</view>
			<view class="topTwo">
				<view class="line">
				</view>
				<view class="text2"> 消费共创价值，共享价值收入 </view>
				<view class="line">
				</view>
			</view>
			<view class="df-sb" style="" v-if="news[0]">
				<u-notice-bar :text="text1" bgColor='#b10021' color="yellow"></u-notice-bar>
				<view class="" style="color: #000;margin-left: 20rpx;" @click="$navTo('/pages/new')"> 更多 </view>
			</view>
			<view class="memberInfo">
				<view class="infoBox" v-if="isLogin">
					<view class="df-sb">
						<view class="df-flex">
							<view class="" style="font-size: 32rpx;font-weight: bold;"> {{userInfo.realname}} </view>
							<view class="" style="margin: 0 13rpx;font-size: 32rpx;"> | </view>
							<view class="df-flex" style="justify-content: center;align-items: center;">
								<image src="/static/image/vip.png" mode="" style="width: 29rpx;height: 20rpx;"></image>
								<view class="" style="font-size: 32rpx;color: #000;margin-left: 10rpx;"> {{grade}}
								</view>
							</view>
						</view>
						<view class="" style="color: #000;font-size: 32rpx;" @click="logout"> 退出 </view>
					</view>
					<view class="infoContent">
						<image :src="userInfo.avatar" mode="" class="avatar" v-if="userInfo.avatar"></image>
						<image src="/static/image/avatar.png" mode="" class="avatar" v-else></image>
						<view class="info">
							<view class="" style="color: darkblue;"> {{userInfo.realname}} </view>
							<view class=""
								style="display: flex;justify-content: space-between;width: 420rpx;color: darkblue;">
								<view class="" style="margin-top: 10rpx;"> {{userInfo.phone}}</view>
								<!-- 	<view class="real" v-if="true" @click="$navTo('/pages/editInfo')">
									<view class="" style="margin-right: 10rpx;">个人信息</view>
									<u-icon name="arrow-right" size="14"></u-icon>
								</view> -->
								<!-- <view class="real" v-if="true" @click="toReal">
									<view class="" style="margin-right: 10rpx;"> 前往实名认证 </view>
									<u-icon name="arrow-right" size="14"></u-icon>
								</view>
								<view class="real" v-else>
									<view class="" style="margin-right: 10rpx;color: #fff;">已完成实名认证 </view>
								</view> -->
								<!-- 	<view class="real" v-if="false" @click="toReal">
									<view class="" style="margin-right: 10rpx;"> 前往实名认证 </view>
									<u-icon name="arrow-right" size="14"></u-icon>
								</view>
								<view class="real" v-else>
									<view class="" style="margin-right: 10rpx;color: #fff;">已完成实名认证 </view>
								</view> -->
							</view>
						</view>
					</view>
				</view>
				<view class="infoBox" v-else>
					<view class="infoContent">
						<view class=""
							style="text-align: center;width: 100%;margin-top: 40rpx;font-size: 32rpx;color: #fff;"
							@click="toLogin"> 点击登录 </view>
					</view>
				</view>
				<view class="jifen">
					<view class="df-flex" style="justify-content: space-between;">
						<view class="tiText"> 当前消费积分：{{point}} </view>
						<view class="ti" @click="$navTo('/pages/promSetting')"> 去提现 </view>
					</view>
					<!-- <view class=""> 积分明细 </view> -->
					<view class="df-sa">
						<view class="" v-for="(item,idx) in tab" :key="idx" @click="select_click(idx,item.id)"
							:class="select_index == idx?'ace':'select_item' ">
							{{item.text}}
						</view>
					</view>
					<scroll-view scroll-y="true" style="height: 350px;margin-top: 30rpx;" @scrolltolower="scrollDown">
						<view class="df-sb ming" v-for="(item,index) in pointList" :key="index" style="margin: 30rpx 0;"
							v-if="!isEmpty" @click="lookDetail(item)">
							<view class="" style="width: 80%;">
								<!-- <view class="title u-line-1" v-if="userInfo.userType==1"> {{item.type_dictText}} </view> -->
								<view class="title u-line-1"> {{item.remark}} </view>
								<view class="time"> {{item.createTime}}</view>
							</view>
							<view class="num" v-if="userInfo.userType==1"><text v-if="item.point>0">+</text>
								{{item.point}}
							</view>
							<view class="num" v-if="userInfo.userType==2"><text v-if="item.point>0">+</text>
								{{item.changePoint}}
							</view>
						</view>
						<!-- 		<view class="" style="display: flex;justify-content: center;margin-top: 100rpx;">
							<image src="/static/image/empty.png" mode="widthFix" v-if="isEmpty" style="width: 500rpx;">
							</image>
						</view> -->
					</scroll-view>
				</view>
				<view class="quan">
					<view class="" style="display: flex;justify-content: center;">
						<image src="/static/image/quan.png" mode="widthFix"></image>
					</view>
					<view class="quanBox df-sa">
						<view class="quanItem">
							<view class="title"> 三级权益 </view>
							<view class="num">
								{{allEquity.three}}
							</view>
						</view>
						<view class="quanItem">
							<view class="title"> 二级权益 </view>
							<view class="num">
								{{allEquity.tow}}
							</view>
						</view>
						<view class="quanItem">
							<view class="title"> 一级权益 </view>
							<view class="num">
								{{allEquity.one}}
							</view>
						</view>
						<view class="quanItem">
							<view class="title"> 特级权益 </view>
							<view class="num">
								{{allEquity.max}}
							</view>
						</view>
					</view>
					<view class="quanBox df-sa">
						<view class="quanItem">
							<view class="title"> 商家补贴权益 </view>
							<view class="num">
								{{allEquity.merchantSubsidy}}
							</view>
						</view>
						<view class="quanItem">
							<view class="title"> 月供权益 </view>
							<view class="num">
								{{allEquity.monthlyPayment}}
							</view>
						</view>
						<view class="quanItem">
							<view class="title"> 工资权益 </view>
							<view class="num">
								{{allEquity.salary}}
							</view>
						</view>
						<view class="quanItem">
							<view class="title"> 募捐权益 </view>
							<view class="num">
								{{allEquity.fundraising}}
							</view>
						</view>
					</view>
				</view>
				<view class="tui" style="justify-content: center;display: flex;">
					<view class="btn" @click="$navTo('/pages/promotion')"> 个人中心 </view>
				</view>
				<view class="" style="justify-content: center;display: flex;" v-if="userInfo.userType==1">
					<view class="btn" @click="toApply"> 申请成为商家 </view>
				</view>
				<view class="" style="justify-content: center;display: flex;" v-if="userInfo.userType==2">
					<view class="btn" @click="$navTo('/pages/gift')"> 商家中心 </view>
				</view>
			</view>
			<u-modal :show="show" title="详情" @confirm="show=false">
				<view class="slot-content">
					<view class="df-flex" style="align-items: center;" v-if="listDetail.type_dictText">
						<view class=""> 类型： </view>
						<view class="" style="width: 400rpx;font-size: 32rpx;"> {{listDetail.type_dictText}}
						</view>
					</view>
					<view class="" style="margin: 20rpx 0;display: flex;">
						<view class=""> 内容： </view>
						<view class="" style="width: 400rpx;font-size: 32rpx;"> {{listDetail.remark}}
						</view>
					</view>
					<view class="df-flex" style="align-items: center;">
						<view class=""> 时间： </view>
						<view class="" style="width: 400rpx;font-size: 32rpx;"> {{listDetail.createTime}}
						</view>
					</view>
				</view>
			</u-modal>
		</view>
	</view>
</template>
<script>
	import {
		getSumByUserId,
		memberPointList,
		getAllEquityByUserId,
		newList,
		shopPointLogList,
		applyStatus,
		getUserInfo,
		dividendList
	} from '../request/api.js'
	let timer = null;
	export default {
		data() {
			return {
				show: false,
				select_index: 0, //当前序号
				isLogin: false,
				quanList: [{
					id: 1,
					text: '三级权益',
					num: 20
				}, {
					id: 2,
					text: '二级权益',
					num: 40
				}, {
					id: 3,
					text: '一级权益',
					num: 60
				}, {
					id: 4,
					text: '特级权益',
					num: 2
				}],
				userInfo: {},
				point: 0,
				pointList: [],
				pageNo: 1,
				total: '',
				allEquity: {},
				grade: '',
				text1: '',
				news: [],
				isEmpty: false,
				select_index: 0, //当前序号
				tab: [{
					id: 1,
					text: '积分明细'
				}, {
					id: 2,
					text: '配股明细'
				}, {
					id: 3,
					text: '分红明细'
				}],
				listDetail: {}
			}
		},
		onLoad() {},
		onShow() {
			if (uni.getStorageSync('token')) {
				this.isLogin = true
				this.getNewList()
			} else {
				uni.showToast({
					title: '请先登录',
					icon: 'none'
				})
				setTimeout(() => {
					this.$navTo('/pages/login')
				}, 2000)
			}
			this.getUserInfoMethod()
		},
		onHide() {
			clearInterval(timer);
			timer = null;
		},
		methods: {
			lookDetail(item) {
				let that = this;
				that.listDetail = item
				console.log(that.listDetail);
				that.show = true
			},
			// tab点击
			select_click(idnex, id) {
				this.select_index = idnex;
				if (this.select_index == 0) {
					//获取积分明细
					this.pointList = []
					this.pageNo = 1
					this.getPointList()
				} else if (this.select_index == 1) {
					//获取配股明细
					this.pointList = []
					this.pageNo = 1
					this.getPointList(4)
				} else if (this.select_index == 2) {
					// 获取分红明细
					this.pointList = []
					this.pageNo = 1
					this.getDividendList()
				}
			},
			getDividendList() {
				let that = this;
				dividendList({
					pageNo: that.pageNo,
					userId: that.userInfo.id
				}).then(res => {
					if (res.code == 200) {
						that.pointList = [...that.pointList, ...res.result.records]
						that.total = res.result.total; //数据总条数
						if (that.pointList.length == 0) {
							that.isEmpty = true
						} else {
							that.isEmpty = false
						}
					}
				})
			},
			//获取用户信息
			getUserInfoMethod() {
				getUserInfo({
					id: uni.getStorageSync('userInfo').id
				}).then(res => {
					if (res.code == 200) {
						this.userInfo = res.result;
						uni.setStorageSync('userInfo', this.userInfo)
						// if (!this.userInfo.idCard) {
						// 	uni.showToast({
						// 		title: '请实名认证',
						// 		icon: 'none'
						// 	})
						// 	setTimeout(() => {
						// 		this.$navTo('/pages/real')
						// 	}, 2000)
						// }
						switch (this.userInfo.grade) {
							case 0:
								this.grade = '普通会员'
								break;
							case 1:
								this.grade = 'vip'
								break;
							case 2:
								this.grade = '员工'
								break;
							case 3:
								this.grade = '领班'
								break;
							case 4:
								this.grade = '店长'
								break;
							case 5:
								this.grade = '经理'
								break;
							case 6:
								this.grade = '总监'
								break;
							case 7:
								this.grade = '董事'
								break;
							default:
								break;
						}
						this.pointList = []
						this.pageNo = 1
						this.getInfo()
						this.getPointList()
						this.getAllEquity()
						timer = setInterval(() => {
							this.getAllEquity()
						}, 5000)
					}
				})
			},
			// 申请成为商家
			toApply() {
				let that = this;
				applyStatus({
					userId: that.userInfo.id
				}).then(res => {
					if (res) {
						that.$navTo('/pages/applyList')
					} else {
						that.$navTo('/pages/applyShop')
					}
				})
			},
			// 获取新闻列表
			getNewList() {
				newList().then(res => {
					if (res.code == 200) {
						this.news = res.result.records
						if (this.news[0]) {
							this.text1 = this.news[0].title
						}
					}
				})
			},
			//触底加载
			scrollDown() {
				if (this.total <= this.pointList.length) {
					uni.showToast({
						title: '已加载全部数据',
						icon: "none"
					});
				} else {
					this.pageNo++;
					if (this.select_index == 0) {
						this.getPointList()
					} else if (this.select_index == 1) {
						this.getPointList(4)
					} else {
						this.getDividendList()
					}
				}
			},
			// 获取当前用户所有的权益包
			getAllEquity() {
				let that = this;
				getAllEquityByUserId({
					userId: that.userInfo.id
				}).then(res => {
					if (res.code == 200) {
						that.allEquity = res.result;
					}
				})
			},
			// 获取用户积分记录表
			getPointList(type) {
				let that = this;
				memberPointList({
					pageNo: that.pageNo,
					memberId: that.userInfo.id,
					type: type
				}).then(res => {
					if (res.code == 200) {
						that.pointList = [...that.pointList, ...res.result.records]
						that.total = res.result.total; //数据总条数
						if (that.pointList.length == 0) {
							that.isEmpty = true
						} else {
							that.isEmpty = false
						}
					}
				})
			},
			// 获取全部积分
			getInfo() {
				let that = this;
				getSumByUserId({
					userId: that.userInfo.id
				}).then(res => {
					if (res.code == 200) {
						that.point = res.result;
					}
				})
			},
			// 退出
			logout() {
				uni.clearStorageSync()
				uni.navigateTo({
					url: '/pages/login'
				})
			},
			//去登录
			toLogin() {
				uni.navigateTo({
					url: '/pages/login'
				})
			},
			//去实名
			toReal() {
				uni.navigateTo({
					url: '/pages/real'
				})
			}
		}
	}
</script>
<style lang="scss">
	.content {
		// height: 100vh;
		// background-color: #252026;
		background: url('/static/image/bg2.png') no-repeat center center;
		background-size: 100% 100%;
		padding: 0 30rpx;
		padding-bottom: 200rpx;

		.topOne {
			justify-content: center;
			display: flex;
			margin-bottom: 45rpx;

			.indexText {
				width: 500rpx;
				height: 170rpx;
				padding-top: 80rpx;
			}
		}

		.topTwo {
			display: flex;
			justify-content: center;
			flex-direction: column;
			align-items: center;
			margin-bottom: 60rpx;

			.line {
				width: 690rpx;
				height: 1px;
				border-top: 1rpx solid;
				border-image: linear-gradient(270deg, rgba(252, 238, 220, 0), rgba(255, 250, 243, 1), rgba(252, 238, 220, 0)) 1 1;
			}

			.text2 {
				width: 480rpx;
				height: 31rpx;
				font-size: 32rpx;
				color: yellow;
				line-height: 31rpx;
				text-align: left;
				font-style: normal;
				text-align: center;
				margin: 13rpx 0;
			}
		}

		.memberInfo {
			color: #000;

			.infoBox {
				padding: 30rpx;

				.infoContent {
					padding: 30rpx;
					margin-top: 32rpx;
					height: 208rpx;
					background: linear-gradient(302deg, #D6B282 0%, #C7A36D 100%);
					border-radius: 30rpx;
					display: flex;

					.avatar {
						width: 120rpx;
						height: 120rpx;
						margin-right: 30rpx;
						font-weight: bold;
						font-size: 32rpx;
						color: #FFFFFF;
						border-radius: 50%;
					}

					.info {
						font-weight: bold;
						font-size: 32rpx;
						color: #000;
						margin-top: 20rpx;
					}

					.real {
						display: flex;
						align-items: center;
						text-align: right;
						font-size: 32rpx;
						color: #68491F;
						text-align: left;
						font-style: normal;
					}
				}
			}
		}

		.jifen {
			width: 100%;
			height: 900rpx;
			margin-top: -80rpx;
			// background: #1C1A1F;
			// background: url('/static/image/index_bg.png') no-repeat center center;
			// background-size: 100% 100%;
			padding: 60rpx 50rpx;

			.tiText {
				font-weight: bold;
				font-size: 32rpx;
				color: yellow;
				line-height: 40rpx;
			}

			// background-color: pink;
			.ti {
				width: 148rpx;
				height: 52rpx;
				border-radius: 26rpx;
				border: 2rpx solid #000;
				font-size: 32rpx;
				color: #000;
				line-height: 52rpx;
				text-align: center;
			}
		}

		.jiDetail {}

		.tabStyle {
			font-weight: bold;
			font-size: 32rpx;
			color: #000;
		}
	}

	.ming {
		.title {
			font-size: 32rpx;
			// color: rgba(255, 255, 255, 0.8);
			color: yellow;
		}

		.time {
			font-size: 32rpx;
			// color: rgba(255, 255, 255, 0.8);
			color: #FFF;
			margin-top: 10rpx;
		}

		.num {
			font-size: 32rpx;
			font-weight: 600;
			color: darkblue;
		}
	}

	.quan {
		width: 100%;
		margin-top: 60rpx;

		.quanBox {
			width: 100%;
			height: 246rpx;

			// background: #d70127;
			.quanItem {
				text-align: center;

				.title {
					font-weight: bold;
					font-size: 32rpx;
					color: #000;
				}

				.num {
					font-weight: bold;
					font-size: 32rpx;
					color: yellow;
					margin-top: 40rpx;
				}

				.point {
					height: 26rpx;
					font-size: 32rpx;
					color: #FDE8CE;
					margin-top: 10rpx;
				}
			}
		}
	}

	.tui {
		margin-top: 80rpx;

		.tuiBox {
			height: 264rpx;
			background: #1C1A1F;
			display: flex;
			// justify-content: center;
			flex-direction: column;
			align-items: center;

			.code {
				margin-top: 60rpx;
			}
		}
	}

	.btn {
		width: 304rpx;
		height: 59rpx;
		line-height: 59rpx;
		background: linear-gradient(#BA986B 0%, #F1DBB6 100%);
		border-radius: 37rpx;
		text-align: center;
		color: #2B1D14;
		font-weight: 600;
		margin-top: 50rpx;
	}

	.ace {
		color: #000;
		font-weight: 600;
		font-size: 32rpx;
		// text-align: center;
		margin-top: 40rpx;
		margin-bottom: 30rpx;
	}

	.select_item {
		color: #000;
		font-weight: 600;
		font-size: 32rpx;
		// text-align: center;
		margin-top: 40rpx;
		margin-bottom: 30rpx;
	}
</style>